//
//  FriendListCell.m
//  project
//
//  Created by 黄建华 on 2018/8/15.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "SortFriendListCell.h"

@implementation SortFriendListCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    
    return self;
}

- (void)createView {
    
    _topImageView = [[UIImageView alloc] init];
    [self addSubview:_topImageView];
    
    _topLabel = [[UILabel alloc] init];
    [self addSubview:_topLabel];
    
    _headImage = [[UIImageView alloc] init];
    [self addSubview:_headImage];
    
    _nickLabel = [[UILabel alloc] init];
    [self addSubview:_nickLabel];
    
    _infoLabel = [[UILabel alloc] init];
    [self addSubview:_infoLabel];
    
    _remarkLabel = [[UILabel alloc] init];
    [self addSubview:_remarkLabel];
    
    _line = [[UIView alloc] init];
    [self addSubview:_line];
    
    _stepImagev = [[UIImageView alloc] init];
    [self addSubview:_stepImagev];
    
    _stepLabel = [[UILabel alloc] init];
    [self addSubview:_stepLabel];
}

//根据高度度求宽度  text 计算的内容  Height 计算的高度 font字体大小
- (CGFloat)getWidthWithText:(NSString *)text height:(CGFloat)height font:(CGFloat)font {
    CGRect rect = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, height)
                                     options:NSStringDrawingUsesLineFragmentOrigin
                                  attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}
                                     context:nil];
    
    return rect.size.width;
}

- (void)updateCellWithModel:(FriednInviterModel *)model {
    _topImageView.frame = SNFRAME(10, 15, 30, 30);
    _topLabel.frame = SNFRAME(10, 15, 30, 30);
    _topLabel.textAlignment = NSTextAlignmentCenter;

    _topImageView.hidden = NO;
    _topLabel.hidden = YES;
    
    if (self.tag == 0) {
        _topImageView.image = [UIImage imageNamed:@"排名1"];
    }
    else if (self.tag == 1) {
        _topImageView.image = [UIImage imageNamed:@"排名2"];
    }
    else if (self.tag == 2) {
        _topImageView.image = [UIImage imageNamed:@"排名3"];
    }
    else
    {
        _topImageView.hidden = YES;
        _topLabel.hidden = NO;
        _topLabel.text = StrByInt(self.tag +1);
    }
    
    
    _headImage.frame               = SNFRAME(50, 5, 50, 50);
    _headImage.layer.masksToBounds = YES;
    _headImage.layer.cornerRadius  = _headImage.width /2.0;
    [_headImage sd_setImageWithURL:[NSURL URLWithString:model.imagePathUrlString] placeholderImage:[UIImage imageNamed:@"loginhead"]];
    // 昵称
    _nickLabel.text      = [NSString stringWithFormat:@"%@", model.remark];
    _nickLabel.textColor = SNCOLORBLACK;
    _nickLabel.frame     = SNFRAME(_headImage.right + 15, 0,screenWidth - _headImage.right - 125, 20);
    _nickLabel.font      = SNFONT(15.0);
    _nickLabel.adjustsFontSizeToFitWidth = YES;
    _nickLabel.minimumScaleFactor = 0.5;
    
    // 备注
    _remarkLabel.text      = [NSString stringWithFormat:@"%@:%@", SN_Text(@"昵称"), model.nickName];
    _remarkLabel.textColor = SNCOLORGRAY;
    _remarkLabel.frame     = SNFRAME(_nickLabel.left, _nickLabel.bottom, 150, 15);
    _remarkLabel.font      = SNFONT(12.0);
    _remarkLabel.adjustsFontSizeToFitWidth = YES;
    _remarkLabel.minimumScaleFactor = 0.5;
//    if ([_remarkLabel.text isEqualToString:SN_Text(@"未填写备注")]) {
//        _remarkLabel.text = @"";
//    }

    //步数
    _stepImagev.image = [UIImage image:@"F步数"];
    _stepImagev.frame = SNFRAME(screenWidth - 50, 3, 40, 40);
    
    //签名
    _infoLabel.text      = [NSString stringWithFormat:@"%@: %@", SN_Text(@"签名"), model.showSign];
    _infoLabel.textColor = SNCOLORGRAY;
    _infoLabel.frame     = SNFRAME(_nickLabel.left, _remarkLabel.bottom,_stepImagev.left -_nickLabel.left, 25);
    float fontsize = FitSimpleSize(8.0, 8.0, 9.0, 10.0, 10.0);
    _infoLabel.font      = SNFONT(fontsize);
    _infoLabel.adjustsFontSizeToFitWidth = YES;
    _infoLabel.minimumScaleFactor = 0.5;
    _infoLabel.numberOfLines = 2;
    
    _stepLabel.textAlignment = NSTextAlignmentCenter;
    _stepLabel.text          = StrByInt(model.step);
    _stepLabel.textColor     = SNCOLORBLACK;
    _stepLabel.frame         = SNFRAME(_stepImagev.left -30, _infoLabel.top - 2, 100, 20);
    _stepLabel.font          = SNSFONT(13.0);
    
    _line.backgroundColor = SNCOLORGRAYLINE;
    _line.frame           = SNFRAME(0, 59, screenWidth, 1);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
